// https://nuxt.com/docs/api/configuration/nuxt-config
import { fileURLToPath } from 'url'

export default defineNuxtConfig({
  compatibilityDate: '2025-05-15',
  ssr: true, // 服务端渲染

  devtools: { enabled: import.meta.env.NODE_ENV === 'development' },
  devServer: {
    port: 4000
  },
  nitro: {
    prerender: {
      routes: ['/']
    },
    devProxy: {
      '/api': {
        target: 'https://api.aiiiin.com',
        changeOrigin: true,
        prependPath: true
      }
    }
  },

  srcDir: 'src/',
  buildDir: '.nuxt', // @default ".nuxt"
  app: {
    baseURL: '/', // @default "/"
    buildAssetsDir: '/_nuxt/', // @default "/_nuxt/"

    head: {
      title: 'Nuxt 3 Demo',
      meta: [{ name: 'description', content: 'Everything about Nuxt 3' }],
      htmlAttrs: {
        'data-theme': 'dark'
      }
      // script: [
      // // <script src="https://myawesome-lib.js"></script>
      //   { src: 'https://awesome-lib.js' }
      // ],
      // link: [
      // // <link rel="stylesheet" href="https://myawesome-lib.css">
      //   { rel: 'stylesheet', href: 'https://awesome-lib.css' }
      // ],
      // // please note that this is an area that is likely to change
      // style: [
      // // <style>:root { color: red }</style>
      //   { textContent: ':root { color: red }' }
      // ],
      // noscript: [
      // // <noscript>JavaScript is required</noscript>
      //   { textContent: 'JavaScript is required' }
      // ]
    },
    pageTransition: { name: 'page', mode: 'out-in' },
    layoutTransition: { name: 'layout', mode: 'out-in' }
  },

  modules: [
    '@nuxt/eslint',
    '@nuxt/fonts',
    '@nuxt/icon',
    '@nuxt/image',
    '@nuxt/scripts',
    '@nuxt/ui',
    '@nuxt/test-utils',
    '@pinia/nuxt',
    'pinia-plugin-persistedstate/nuxt',
    '@nuxtjs/tailwindcss',
    '@vueuse/nuxt'
  ],
  // 功能不成熟
  image: {
    // dir: 'assets/images',
    // dir: 'public'
    domains: ['https://www.tailwindcss.cn'],
    aliyun: {
      baseURL: 'https://assets.yanbot.tech'
    }
  },
  /** https://icones.js.org
   * <Icon name="uil:github" />
   */
  icon: {
    mode: 'css',
    cssLayer: 'base', // When using TailwindCSS v4 with the css mode, you should configure the cssLayer in Nuxt's app config
    customCollections: [
      /**
        <template>
          <Icon name="my-icon:test" />
          <Icon name="my-icon:close" />
        </template>
       */
      {
        prefix: 'my-icon',
        dir: './src/assets/my-icons',
        normalizeIconName: false
      }
    ]
  },
  /**
   * const weightMap: Record<string, string> = {
      100: 'thin',
      200: 'extra-light',
      300: 'light',
      400: 'normal',
      500: 'medium',
      600: 'semi-bold',
      700: 'bold',
      800: 'extra-bold',
      900: 'black',
    }
   */
  // fonts: {
  //   defaults: {
  //     preload: true,
  //     weights: [100, 300, 400, 500, 700, 900]
  //   },
  //   families: [
  //     {
  //       name: 'HarmonyOS_Sans_SC',
  //       global: true,
  //       provider: 'local',
  //       // weights: [100],
  //       src: [
  //         {
  //           url: '/fonts/HarmonyOS_Sans_SC_Thin.woff2',
  //           format: 'woff2'
  //         }
  //       ]
  //     },
  //     {
  //       name: 'HarmonyOS_Sans_SC',
  //       global: true,
  //       provider: 'local',
  //       // weights: [300],
  //       src: [
  //         { url: '/fonts/HarmonyOS_Sans_SC_Light.woff2', format: 'woff2' }
  //       ]
  //     },
  //     {
  //       name: 'HarmonyOS_Sans_SC',
  //       global: true,
  //       provider: 'local',
  //       // weights: [400],
  //       src: [
  //         { url: '/fonts/HarmonyOS_Sans_SC_Regular.woff2', format: 'woff2' }
  //       ]
  //     },
  //     {
  //       name: 'HarmonyOS_Sans_SC',
  //       global: true,
  //       provider: 'local',
  //       // weights: [500],
  //       src: [
  //         { url: '/fonts/HarmonyOS_Sans_SC_Medium.woff2', format: 'woff2' }
  //       ]
  //     },
  //     {
  //       name: 'HarmonyOS_Sans_SC',
  //       global: true,
  //       provider: 'local',
  //       // weights: [700],
  //       src: [
  //         { url: '/fonts/HarmonyOS_Sans_SC_Bold.woff2', format: 'woff2' }
  //       ]
  //     },
  //     {
  //       name: 'HarmonyOS_Sans_SC',
  //       global: true,
  //       provider: 'local',
  //       // weights: [900],
  //       src: [
  //         { url: '/fonts/HarmonyOS_Sans_SC_Black.woff2', format: 'woff2' }
  //       ]
  //     }
  //   ]
  // },

  components: [
    {
      path: '~/components',
      pathPrefix: false, // 仅基于组件名称而非路径进行自动导入
      extensions: ['.vue']
    }
  ],
  // css应用到应用的所有页面
  css: ['animate.css', '~/assets/css/main.css', '~/assets/css/my-theme.scss'],
  // NuxtUI
  ui: {
    theme: {
      colors: ['primary', 'secondary', 'success', 'info', 'warning', 'error', 'custom', 'myCustom']
    }
  },
  // 通过tailwind.config.ts配置
  // tailwindcss: {
  //   cssPath: '~/assets/css/tailwind.css',
  //   config: {
  //     content: [
  //       './components/**/*.{js,vue,ts}',
  //       './layouts/**/*.vue',
  //       './pages/**/*.vue',
  //       './plugins/**/*.{js,ts}',
  //       './nuxt.config.{js,ts}',
  //       './app.vue'
  //     ],
  //     theme: {
  //       extend: {
  //         colors: { tikeyc: 'red' }
  //       }
  //     }
  //   }
  // },
  postcss: {
    plugins: {
      // tailwindcss: {},
      // autoprefixer: {}
    }
  },
  alias: {
    images: fileURLToPath(new URL('./assets/images', import.meta.url)),
    style: fileURLToPath(new URL('./assets/style', import.meta.url)),
    data: fileURLToPath(new URL('./assets/other/data', import.meta.url))
  },

  imports: {
    dirs: [
      // 自动导入 composables 目录下的文件
      '~/composables',
      // ... 或扫描具有特定名称和文件扩展名的嵌套一层深的可组合项
      '~/composables/*/index.{ts,js,mjs,mts}'
    ]
  },

  // pnpm add -D vue-tsc typescript
  typescript: {
    typeCheck: true
  },

  runtimeConfig: {
    // 仅在服务器端可用的私有键 访问 useRuntimeConfig().apiSecret
    apiSecret: '123',
    apiServerBase: '/api',
    // public 中的键也会暴露到客户端 访问 useRuntimeConfig().public.apiBase
    public: {
      apiBase: '/api',
      testValue: '' // 在.env中配置覆盖
    },
    nitro: {
      envPrefix: 'NUXT_' // 环境变量前缀
    }
  },

  $development: {},
  $test: {},
  $production: {},
  $env: {
    staging: {}
  },

  routeRules: {
    '/': { prerender: true },
    '/about': { prerender: true }
  },
  plugins: [],
  // 默认使用vite
  vite: {
    plugins: [],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "~/assets/css/variables.scss" as *;'
        }
      }
    }
  }
  // webpack: {},
})
